<template>
	<view >
		<custom-navigation-bar title="分享记录"></custom-navigation-bar> 
		  
		<view class="top05" style="height: 150rpx;"></view> 
		<view style="width: 100%;height: 20rpx;float: left;"></view>  
		<view v-if="data.length>0">
			<view class="xiaoqu_item" v-for="(item,index) in data" :key="index">
				<view style="width: 90%;margin-left: 5%;float: left;">
					商品名：{{item.name}}
				</view>
				<view style="width: 90%;margin-left: 5%;float: left;">
					分享数：{{item.shareNums}}&nbsp;&nbsp;订单数：{{item.orderNums}}
				</view> 
			</view>
			<view class="more" v-if="more" @click="getMore()">
			     加载更多
			</view>
			<view class="more" v-if="!more">
			     无更多数据
			</view>
		</view>
		 <view class="more" v-if="data.length==0">
		      暂无数据
		 </view>
		<view style="width: 100%;height: 60rpx;float: left;"></view>
	</view>
	
	<uni-popup ref="popup" background-color="#fff">
		<view class="popup-content" :class="{ 'popup-height': type === 'left' || type === 'right' }">
			<view class="box_title1"  >
				添加小区
				<image src="../../static/close.png" class="xieyi_img" @click="closeToggle"></image>
			</view>
			<view>
				<input  type="text" class="input" v-model="village.name" maxlength="20"  placeholder="请输入小区名称" />
				<view class="btn" @click="submit()">
					确定
				</view>
			</view>
		</view>
	</uni-popup>
</template>

<script setup>
	import CustomNavigationBar from '@/components/CustomNavigationBar.vue'; 
	import { ref } from "vue"; 
	import http from '../../../utils/http';
	const village=ref({id:0,name:''});
	const id=ref(0);
	const userId=ref();
	import {
		onLoad,
		onPageScroll
	} from '@dcloudio/uni-app';
	onLoad((query) => {
		id.value=query.id;
		userId.value=getApp().globalData.user.userId
		// id.value=4;
		// userId.value=24;
		initData();
	})
   
	const data=ref([]);
	const pageIndex=ref(1);
	const pageSize=ref(15);
	const more=ref(true);
	function initData(){
		uni.showLoading({
			title: '数据加载中',
			mask:true
		}); 
		http.request({
		 	url: "/butler/share/log",
		 	method: "POST",
		 	data: { 
				userId:userId.value,
				pageIndex:pageIndex.value,
				pageSize:pageSize.value
		 	}
		}).then((responseData) => { 
			uni.hideLoading();
			if(responseData.code==1){
				if(pageIndex.value==1){
					data.value=responseData.data;
				}else{
					if(responseData.data.length==0){
						more.value=false;
					}else{
						for(var i=0;i<responseData.data.length;i++){
							data.value.push(responseData.data[i])
						} 
					}
				}
			}else if(responseData.code==0){
				uni.showToast({
					icon: 'error',
					title: responseData.message
				})
			}else if(responseData.code==-1){
				uni.navigateTo({
					url: "/pages/login/login"
				});
			}
		}).catch((err) => {
			uni.hideLoading();
		 	uni.showToast({
		 		icon: 'error',
		 		title: '请求失败'
		 	})
		})
	}
	function getMore(){
		pageIndex.value=pageIndex.value+1;
		initData();
	}
	 
</script>

<style>
	@import "../../list/list.scss";
	@import "../../login/xieyi.scss";
	 .xiaoqu_item{
		 width: 90%;float: left;margin-left: 5%;background: white;margin-top: 20rpx;line-height: 50rpx;border-radius: 20rpx;
	 }
	 .more{
		 width: 100%;text-align: center;line-height: 50rpx;color: #666666;font-size: 25rpx;float: left;margin-top: 10rpx;
	 }
	 .edit{
		 float: right;color: dodgerblue;margin-right: 50rpx;
	 }
</style>